// @APIVersion 1.0.0
// @Title 小二菜单API
// @Description 小二菜单API
// @Contact 896144801@qq.com

package routers

import (
	"github.com/astaxie/beego"
	"xiaoercaidan/webPage/controllers"
	"github.com/astaxie/beego/plugins/cors"
)

func init() {
	beego.Router("/", &controllers.PageController{}, "*:DefaultIndex")
	beego.Router("/index", &controllers.PageController{}, "*:Index")

	pagesNs := beego.NewNamespace("/v1",

		beego.NSNamespace("/pages",
			beego.NSRouter("/test/demo1", &controllers.PageController{}, "*:Demo1"),
			beego.NSRouter("/test/demo2", &controllers.PageController{}, "*:Demo2"),
			beego.NSRouter("/test/demo3", &controllers.PageController{}, "*:Demo3"),
			beego.NSRouter("/test/main", &controllers.PageController{}, "*:Main"),
			beego.NSRouter("/test/user/manager", &controllers.PageController{}, "*:UserManager"),
			beego.NSRouter("/test/shop/manager", &controllers.PageController{}, "*:ShopManager"),
			beego.NSRouter("/test/goods/manager", &controllers.PageController{}, "*:GoodsManager"),
			beego.NSRouter("/test/login", &controllers.PageController{}, "*:Login"),

			beego.NSRouter("/", &controllers.PageController{}, "*:DefaultIndex"),
			beego.NSRouter("/index", &controllers.PageController{}, "*:Index"),
			//beego.NSRouter("/login", &controllers.PageController{}, "*:Login"),
			//beego.NSRouter("/login", &controllers.PageController{}, "*:Login"),
			//beego.NSRouter("/login", &controllers.PageController{}, "*:Login"),
			//beego.NSRouter("/login", &controllers.PageController{}, "*:Login"),
			//beego.NSRouter("/login", &controllers.PageController{}, "*:Login"),
		),


		beego.NSNamespace("/apis",
			beego.NSRouter("/logout", &controllers.BusinessController{}, "*:Logout"),
			beego.NSRouter("/getUserInfo", &controllers.BusinessController{}, "*:GetUserInfo"),
			beego.NSNamespace("/user",
				beego.NSInclude(
					&controllers.UserController{},
				),
			),
			beego.NSNamespace("/goods",
				beego.NSInclude(
					&controllers.GoodsController{},
				),
			),
			beego.NSNamespace("/shop",
				beego.NSInclude(
					&controllers.ShopController{},
				),
			),

		),
	)

	beego.AddNamespace(pagesNs)

	beego.InsertFilter("*", beego.BeforeRouter, cors.Allow(&cors.Options{
		AllowAllOrigins:  true,
		AllowMethods:     []string{"*"},
		AllowHeaders:     []string{"Origin", "Authorization", "Access-Control-Allow-Origin"},
		ExposeHeaders:    []string{"Content-Length", "Access-Control-Allow-Origin"},
		AllowCredentials: true,
	}))

}

